package org.example;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.List;

public class RedisDemoString {
    private static void test1(Jedis jedis) {
        System.out.println("mget 和 mset");
        jedis.flushAll();
        jedis.mset("key1","1111","key2","2222","key3","3333");
        List<String> mget = jedis.mget("key1", "key111","key2", "key3");
        System.out.println(mget);
    }
    private static void test2(Jedis jedis){
        System.out.println("getrange 和 setrange");
        jedis.flushAll();
        jedis.set("key","abcdefg");
        String key = jedis.getrange("key", 0, 3);
        System.out.println(key);
        jedis.setrange("key",0,"aaaa");
        String key1 = jedis.get("key");
        System.out.println(key1);
    }
    private static void test3(Jedis jedis){
        System.out.println("append");
        jedis.flushAll();
        jedis.set("key","1111");
        jedis.append("key","2222");
        String key = jedis.get("key");
        System.out.println( key);
    }
    private static void test4(Jedis jedis){
        System.out.println("incr 和 decr");
        jedis.flushAll();
        jedis.set("key","100");
        long result = jedis.incr("key");
        System.out.println(result);
        String key = jedis.get("key");
        System.out.println(key);
        result = jedis.decr("key");
        System.out.println(result);
        key = jedis.get("key");
        System.out.println(key);
    }
    public static void main(String[] args) {
        JedisPool jedisPool=new JedisPool("tcp://127.0.0.1:8888");
        try (Jedis jedis=jedisPool.getResource()){
//            test1(jedis);
//            test2(jedis);
//            test3(jedis);
            test4(jedis);

        }
    }



}
